﻿using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace Cubicle.Core.Hosting
{
    public static class HostingExtensions
    {
        #region Runtime Known type serialization

        //[MethodImpl(MethodImplOptions.NoInlining)]
        //public static void AddGenericResolver(this ServiceHost host)
        //{
        //    Debug.Assert(host.State != CommunicationState.Opened);

        //    foreach (var endpoint in host.Description.Endpoints)
        //        AddGenericResolver(endpoint);
        //}

        //[MethodImpl(MethodImplOptions.NoInlining)]
        //public static void AddGenericResolver<T>(this ClientBase<T> proxy) where T : class
        //{
        //    Debug.Assert(proxy.State != CommunicationState.Opened);
        //    AddGenericResolver(proxy.Endpoint);
        //}

        //[MethodImpl(MethodImplOptions.NoInlining)]
        //public static void AddGenericResolver<T>(this ChannelFactory<T> factory) where T : class
        //{
        //    Debug.Assert(factory.State != CommunicationState.Opened);
        //    AddGenericResolver(factory.Endpoint);
        //}

        //static void AddGenericResolver(ServiceEndpoint endpoint)
        //{
        //    foreach (var operation in endpoint.Contract.Operations)
        //    {
        //        var behavior = operation.Behaviors.Find<DataContractSerializerOperationBehavior>();
        //        behavior.DataContractResolver = new EngineContractResolver();
        //    }
        //}

        #endregion

    }
}
